package com.nbsaas.boot.shiro3.thread;

/**
 * 租户计算的时候的线程变量
 */
public class TenantThreadLocal {

    private static final ThreadLocal<String> contextHolder = new ThreadLocal<>();

    private static final ThreadLocal<String> urlHolder = new ThreadLocal<>();

    private static final InheritableThreadLocal<Long> tenantHolder = new InheritableThreadLocal<>();

    public static void setTenantKey(String key) {
        contextHolder.set(key);
    }

    public static String getTenantKey() {
        return contextHolder.get();
    }

    public static String getUrl() {
        return urlHolder.get();
    }

    public static void setUrl(String url) {
        urlHolder.set(url);
    }

    public static void setTenant(Long key) {
        tenantHolder.set(key);
    }

    public static Long getTenant() {
        return tenantHolder.get();
    }

    public static void clear() {
        contextHolder.remove();
    }
    public static void clearTenant() {
        tenantHolder.remove();
        urlHolder.remove();
    }
}
